package com.mp.approvalreq.servlet;

import com.mp.approvalreq.entity.TemplateFolder;
import com.mp.approvalreq.service.TemplateServicePrx;
import com.mp.user.entity.User;
import com.plusmoney.util.ParameterUtils;
import com.qq.tars.client.util.ServantUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteTemplateGroup")
public class DeleteTemplateGroup extends AbstractServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            User user = getReqUser(req);

            Integer id = ParameterUtils.getIntegerParameter(req, "id");

            TemplateFolder folder = new TemplateFolder();
            folder.setId(id);
            folder.setUser(user);

            TemplateServicePrx templateServicePrx = ServantUtils.getObject(TemplateServicePrx.class);
            templateServicePrx.deleteTemplateFolder(folder);

            printSuccessJson(resp);
        } catch (Throwable throwable) {
            onThrowable(req, resp, throwable);
        }
    }
}
